from PySide import QtGui, QtCore
import g_view

class EditSettings(QtGui.QWidget):

	def __init__(self, parent):
		super(EditSettings, self).__init__()
		self.parent = parent
		self.initUI()

	def initUI(self):
		
		model = QtGui.QGroupBox("Model Settings:")
		hbox1 = QtGui.QHBoxLayout()
		dimension = QtGui.QLabel("Number Of Dimensions")
		hbox1.addWidget(dimension)
		self.dimensionedit = QtGui.QLineEdit()
		self.dimensionedit.setValidator(QtGui.QIntValidator())
		hbox1.addWidget(self.dimensionedit)
		hbox2 = QtGui.QHBoxLayout()
		timestep = QtGui.QLabel("Time Step")
		hbox2.addWidget(timestep)
		self.timestepedit = QtGui.QLineEdit()
		self.timestepedit.setValidator(QtGui.QDoubleValidator())
		hbox2.addWidget(self.timestepedit)
		vbox1 = QtGui.QVBoxLayout()
		vbox1.addLayout(hbox1)
		vbox1.addLayout(hbox2)
		model.setLayout(vbox1)
		
		graphics = QtGui.QGroupBox("Graphics Settings:")
		hbox3 = QtGui.QHBoxLayout()
		scale = QtGui.QLabel("Scale")
		hbox3.addWidget(scale)
		self.scaleedit = QtGui.QLineEdit()
		self.scaleedit.setValidator(QtGui.QDoubleValidator())
		hbox3.addWidget(self.scaleedit)
		self.showorigin = QtGui.QCheckBox("Show Origin")
		self.shownodes = QtGui.QCheckBox("Show Nodes")
		self.shownodenames = QtGui.QCheckBox("Show Node Names")
		self.showmembers = QtGui.QCheckBox("Show Members")
		self.showmembernames = QtGui.QCheckBox("Show Member Names")
		vbox2 = QtGui.QVBoxLayout()
		vbox2.addLayout(hbox3)
		vbox2.addWidget(self.showorigin)
		vbox2.addWidget(self.shownodes)
		vbox2.addWidget(self.shownodenames)
		vbox2.addWidget(self.showmembers)
		vbox2.addWidget(self.showmembernames)
		graphics.setLayout(vbox2)
		
		self.updatebutton = QtGui.QPushButton("Update Settings")
		self.updatebutton.clicked.connect(self.modifySettings)
		
		editdialog = QtGui.QVBoxLayout()
		editdialog.addWidget(model)
		editdialog.addStretch(1)
		editdialog.addWidget(graphics)
		editdialog.addStretch(1)
		editdialog.addWidget(self.updatebutton)
		
		self.setLayout(editdialog)
		self.setWindowTitle("Edit Settings")
		self.updateSettings()
	
	def modifySettings(self):
		self.parent.data.settings.dimensions = int(self.dimensionedit.text())
		self.parent.data.settings.timestep = float(self.timestepedit.text())
		temp = float(self.scaleedit.text())
		self.parent.data.settings.showorigin = self.showorigin.isChecked()
		self.parent.data.settings.shownodes = self.shownodes.isChecked()
		self.parent.data.settings.shownodenames = self.shownodenames.isChecked()
		self.parent.data.settings.showmembers = self.showmembers.isChecked()
		self.parent.data.settings.scale = float(self.scaleedit.text())
		self.parent.data.settings.showmembernames = self.showmembernames.isChecked()
		self.parent.updateAll()
	
	def updateSettings(self):
		self.dimensionedit.setText(str(self.parent.data.settings.dimensions))
		self.timestepedit.setText(str(self.parent.data.settings.timestep))
		self.scaleedit.setText(str(self.parent.data.settings.scale))
		self.showorigin.setChecked(self.parent.data.settings.showorigin)
		self.shownodes.setChecked(self.parent.data.settings.shownodes)
		self.shownodenames.setChecked(self.parent.data.settings.shownodenames)
		self.showmembers.setChecked(self.parent.data.settings.showmembers)
		self.showmembernames.setChecked(self.parent.data.settings.showmembernames)
	
	def closeEvent(self, event):
		self.hide()
